package ibm.cognos.imt.template

import groovy.xml.MarkupBuilder

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/9/14
 * Time: 2:24 PM
 * To change this template use File | Settings | File Templates.
 */
class ListItemTemplate extends AbstractTemplate {
    def name

    ListItemTemplate (n) {
        name = n
    }


    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.listColumn {
            listColumnTitle {
                style {
                    defaultStyles {
                        defaultStyle(refStyle: "lt")
                    }
                }
                contents {
                    textItem {
                        dataSource {
                            dataItemLabel(refDataItem: "${name}")
                        }
                    }
                }
            }
            listColumnBody {
                style {
                    defaultStyles {
                        defaultStyle(refStyle: "lm")
                    }
                }
                contents {
                    textItem {
                        dataSource {
                            dataItemValue(refDataItem: "${name}")
                        }
                    }
                }
            }

        }
    }

    @Override
    def getTemplateNode() {
        root = new XmlSlurper(false, false).parseText(getSpecStr())
        root
    }
}
